<?php

namespace App\Admin\Actions\Import;

use App\Models\Department;
use App\Models\DepartmentFile;
use Dcat\Admin\Widgets\Modal;

class ImportPDFAction
{
    protected $title = '<a href="javascript:void(0)" class="btn btn-primary">点击上传</a>';
    protected $relation_table;
    protected $file_type;
    protected $department;
    protected $office_file_type;
    protected $icon;
    protected $office_file_type_name;

    public function __construct(Department $department, $office_file_type = DepartmentFile::OFFICE_FILE_TYPE_PDF)
    {
        $this->department = $department;
        $this->file_type = $department->file_type;
        $this->office_file_type = $office_file_type;
        if ($this->office_file_type == DepartmentFile::OFFICE_FILE_TYPE_PDF) {
            $this->icon =  '<i class="iconfont icon-pdf"></i>&nbsp;上传PDF';
        } else {
            $this->icon =  '<i class="iconfont icon-ppt"></i>&nbsp;上传PPT';
        }
        $this->title = '<a href="javascript:void(0)" class="btn btn-primary">'.$this->icon.'</a>';
    }
    public function render()
    {
        // 实例化表单类并传递自定义参数
        $form = ImportPDFForm::make()->payload(['dwdm' => $this->department->dwdm, 'file_type' => $this->file_type, 'office_file_type' => $this->office_file_type]);

        return Modal::make()
            ->lg()
            ->title('上传')
            ->body($form)
            ->button($this->title);
    }
}